Advanced Concurrency in Java by Ajay Kumar

Advanced Concurrency in Java by Ajay Kumar

Author:Ajay Kumar [Kumar, Ajay]
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2018-11-13T16:00:00+00:00


Java Coding Wrap-up

How to properly lock a Producer / Consumer with Lock

How to deal with exceptions and timeout

How HashMapcan fail in a concurrent application

How to properly synchronize it using a pair of read / write locks

So let us quickly wrap up this Java coding session. What did we see in the code? First of all, we saw how to properly lock the producer/consumer pattern with instances of this lock interface, which is ReentrantLock. We then saw how it was possible to deal with exceptions properly and timeouts using this pattern, which was not possible with the object.wait and notify pattern. And in a second example, we saw the HashMap in action in a concurrent environment and how easy it is to make it fail in such an environment. The HashMap implementation is not thread-safe, so do not use it in a concurrent application without precautions. So we also saw how to properly synchronize it, and for that, we used a pair of read/write locks. We did that to ensure a better throughput, especially with parallel read operations on this map and handle than the fully-synchronized version of the HashMap you can build using the collections.SynchronizeMap method. Last note on this point, we will also see thread-safe implementations of maps, concurrent skip list maps, and concurrent HashMaps in the last module of this book.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.